﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<NewsInformation>
@{
    this.ViewBag.Title = "Nyhedsinformation";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var funds = this.ViewData["Funds"] as List<Fund> ?? new List<Fund>();
    List<NewsInformationType> types = this.ViewData["Types"] as List<NewsInformationType> ?? new List<NewsInformationType>();
    DefaultSearchFields defaultFields = this.ViewData["DefaultFields"] as DefaultSearchFields ?? new DefaultSearchFields();
    var criteriaFunds = this.ViewData["CriteriaFunds"] as List<Guid> ?? new List<Guid>();
    var criteriaType = this.ViewData["CriteriaType"] as Guid?;
}
<h2>Søgeresultat - @ViewBag.Title</h2>

<fieldset class="searchCriterias">
    <legend>Søgning</legend>
    <table>    
        <tr>
            <td>Type:</td><td>@ViewBag.Title</td>
        </tr>
        <tr><td>Antal resultater i alt: </td><td>@Model.TotalRows</td></tr>
        @if (criteriaFunds.Any())
        {
            <tr><td>Fonde og puljer: </td>
                <td>
                    @foreach (Fund fund in funds.Where(x => criteriaFunds.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @fund.Name
                        <br />
                    }
                </td>
            </tr>
        }
        @if (criteriaType.HasValue && criteriaType.Value != Guid.Empty)
        {
            <tr><td>Nyheds-type:</td><td>@types.Single(x => x.ID == criteriaType.Value).Name</td></tr>
        }
        @Html.Partial("~/Views/Reports/_SearchDefaultFieldsParametersTableTR.cshtml", defaultFields)

    </table>
</fieldset>


<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
    </tr>
    @if (this.Model != null)
    {
        foreach (NewsInformation news in this.Model.List)
        {
            <tr>
                <td>@string.Format("{0:dd-MM-yyyy}", news.TimeOfActivity)</td>
                <td>@news.Name</td>
            
                <td>
                    @if (types.Where(x => x.ID == news.Type).Any())
                    {
                        @types.SingleOrDefault(x => x.ID == news.Type).Name
                    }
                </td>
                <td>
                    @(news.IsInformationAboutFunds ? "Fonde/puljer" : string.Empty)
                    @(news.IsInformationAboutProgress ? "Fremdrift" : string.Empty)
                    @(news.IsInformationAboutResults ? "Resultater" : string.Empty)
                </td>
                <td>
                    @if (news.Comments.Length < 30)
                    {
                        @news.Comments
                    }
                    else
                    {
                        @(string.Format("{0}...", news.Comments.Substring(0, 30)))
                    }
                </td>
            </tr>
        }
        <tr><td colspan="5"></td></tr>
    }
    </table>